import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
// 1导入element
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
// 1导入element icon图标库（先安装包管理器）
import * as ElementPlusIconsVue from "@element-plus/icons-vue";

// 导入封装的请求
import axios from "axios";
import request from "./utils/axios";

// 导入iconfont
import "./assets/iconfont.css";

var app = createApp(App);
app.use(store).use(router).mount("#app");

// 全局挂载请求
app.config.globalProperties.$axios = request;

// 请求拦截器(这样需要带请求头header就不用了)
axios.interceptors.request.use(
  (config) => {
    if (localStorage.getItem("token")) {
      (config.headers as any)["Authorization"] = localStorage.getItem("token");
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
// 2注册element
app.use(ElementPlus);
// 2 注册使用icon 图标库
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

// 图表echarts
import "echarts";
